package com.xueyi.aixihu.utils;

import com.xueyi.aixihu.config.SpringContextConfig;
import com.xueyi.aixihu.entity.generatedMapper.AxhFinanceLogMapper;
import com.xueyi.aixihu.entity.generatedMapper.AxhUserLogMapper;
import com.xueyi.aixihu.entity.po.AxhFinanceLog;
import com.xueyi.aixihu.entity.po.AxhUserLog;
import com.xueyi.aixihu.entity.po.DtNewsSort;
import com.xueyi.aixihu.entity.vo.DtUsersVo;

/**
 * 描述 日志工具类
 *
 * @auther 俞烨
 * @date 2022-08-17 10
 */
public class LogUtil {


    public static final AxhFinanceLogMapper AXH_FINANCE_LOG_MAPPER = SpringContextConfig.getBean(AxhFinanceLogMapper.class);
    public static final AxhUserLogMapper AXH_USER_LOG_MAPPER = SpringContextConfig.getBean(AxhUserLogMapper.class);

    /**
     * 构建财务日志
     *
     * @param financeId
     * @param content
     * @param dtUsersVo
     * @param areaFromToId
     */
    public static void buildFinanceLog(Integer financeId, String content, DtUsersVo dtUsersVo, Integer areaFromToId, Integer status) {

        buildFinanceLog(financeId, content, dtUsersVo, areaFromToId, status, null);
    }

    public static void buildFinanceLog(Integer financeId, String content, DtUsersVo dtUsersVo, Integer areaFromToId, Integer status, String remark) {
        AxhFinanceLog axhFinanceLog = new AxhFinanceLog();
        axhFinanceLog.setFinanceId(financeId);
        axhFinanceLog.setCommandUserId(dtUsersVo.getId());
        axhFinanceLog.setLogContent(content);
        axhFinanceLog.setCurrentFinanceStatus(status);
        axhFinanceLog.setRemark(remark);
        AXH_FINANCE_LOG_MAPPER.insertSelective(axhFinanceLog);

        // 添加系统的日志
        buildUserLog(financeId.toString(), content, dtUsersVo, areaFromToId);
    }

    /**
     * 构建用户的操作日志
     *
     * @param otherId      涉及到删、修、增等操作需要记录主键id，多个用逗号隔开，可为空
     * @param content      日志的内容 不可为空 格式为：【{模块名称}】用户{用户名}{新增、修改、删除}{业务具体的内容}
     *                     如： 【财务报表】用户{俞烨}{创建了}{财务报表，并导入了Excel}
     * @param dtUsersVo    操作的用户
     * @param fromToAreaId 日志动态属于哪个小区
     */
    public static void buildUserLog(String otherId, String content, DtUsersVo dtUsersVo, Integer fromToAreaId) {

        AxhUserLog axhUserLog = new AxhUserLog();
        axhUserLog.setCommandUserId(dtUsersVo.getId());
        axhUserLog.setLogContent(content);
        axhUserLog.setOtherId(otherId);
        axhUserLog.setFromToAreaId(fromToAreaId);
        AXH_USER_LOG_MAPPER.insertSelective(axhUserLog);
    }
}
